#include "widget.h"
#include "ui_widget.h"
#include <QPainter>
#include <QImage>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    QImage img(500, 500, QImage::Format_RGB32);
    img.fill(Qt::white); // 填充白色，背景默认黑色
    QPainter painter(&img);
    painter.drawEllipse(QPoint(100, 100), 100, 100);

    // 保存
    img.save(".\\tmp.jpg");
}

Widget::~Widget()
{
    delete ui;
}

void Widget::paintEvent(QPaintEvent *event)
{
    QPainter painter(this);
    QImage img;
    // 加载图片
    img.load(".\\tmp.jpg");
    // 修改像素点
    for (int i = 100; i < 200; i++) {
        for (int j = 100; j < 200; j++) {
            QRgb rgb = qRgb(0, 0, 255);
            img.setPixel(i, j, rgb);
        }
    }

    painter.drawImage(0, 0, img);

}

